home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / DCACHE.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  6KB  |  195 lines

  1. #ifndef __LINUX_DCACHE_H
  2. #define __LINUX_DCACHE_H
  3.  
  4. #ifdef __KERNEL__
  5.  
  6. /*
  7.  * linux/include/linux/dcache.h
  8.  *
  9.  * Dirent cache data structures
  10.  *
  11.  * (C) Copyright 1997 Thomas Schoebel-Theuer,
  12.  * with heavy changes by Linus Torvalds
  13.  */
  14.  
  15. #define D_MAXLEN 1024
  16.  
  17. #define IS_ROOT(x) ((x) == (x)->d_parent)
  18.  
  19. /*
  20.  * "quick string" -- eases parameter passing, but more importantly
  21.  * saves "metadata" about the string (ie length and the hash).
  22.  */
  23. struct qstr {
  24.     const unsigned char * name;
  25.     unsigned int len;
  26.     unsigned int hash;
  27. };
  28.  
  29. /* Name hashing routines. Initial hash value */
  30. #define init_name_hash()        0
  31.  
  32. /* partial hash update function. Assume roughly 4 bits per character */
  33. static __inline__ unsigned long partial_name_hash(unsigned long c, unsigned long prevhash)
  34. {
  35.     prevhash = (prevhash << 4) | (prevhash >> (8*sizeof(unsigned long)-4));
  36.     return prevhash ^ c;
  37. }
  38.  
  39. /* Finally: cut down the number of bits to a int value (and try to avoid losing bits) */
  40. static __inline__ unsigned long end_name_hash(unsigned long hash)
  41. {
  42.     if (sizeof(hash) > sizeof(unsigned int))
  43.         hash += hash >> 4*sizeof(hash);
  44.     return (unsigned int) hash;
  45. }
  46.  
  47. /* Compute the hash for a name string. */
  48. static __inline__ unsigned int full_name_hash(const unsigned char * name, unsigned int len)
  49. {
  50.     unsigned long hash = init_name_hash();
  51.     while (len--)
  52.         hash = partial_name_hash(*name++, hash);
  53.     return end_name_hash(hash);
  54. }
  55.  
  56. #define DNAME_INLINE_LEN 16
  57.  
  58. struct dentry {
  59.     int d_count;
  60.     unsigned int d_flags;
  61.     struct inode  * d_inode;    /* Where the name belongs to - NULL is negative */
  62.     struct dentry * d_parent;    /* parent directory */
  63.     struct dentry * d_mounts;    /* mount information */
  64.     struct dentry * d_covers;
  65.     struct list_head d_hash;    /* lookup hash list */
  66.     struct list_head d_lru;        /* d_count = 0 LRU list */
  67.     struct list_head d_child;    /* child of parent list */
  68.     struct list_head d_subdirs;    /* our children */
  69.     struct list_head d_alias;    /* inode alias list */
  70.     struct qstr d_name;
  71.     unsigned long d_time;        /* used by d_revalidate */
  72.     struct dentry_operations  *d_op;
  73.     struct super_block * d_sb;    /* The root of the dentry tree */
  74.     unsigned long d_reftime;    /* last time referenced */
  75.     void * d_fsdata;        /* fs-specific data */
  76.     unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */
  77. };
  78.  
  79. struct dentry_operations {
  80.     int (*d_revalidate)(struct dentry *);
  81.     int (*d_hash) (struct dentry *, struct qstr *);
  82.     int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);
  83.     void (*d_delete)(struct dentry *);
  84.     void (*d_release)(struct dentry *);
  85.     void (*d_iput)(struct dentry *, struct inode *);
  86. };
  87.  
  88. /* the dentry parameter passed to d_hash and d_compare is the parent
  89.  * directory of the entries to be compared. It is used in case these
  90.  * functions need any directory specific information for determining
  91.  * equivalency classes.  Using the dentry itself might not work, as it
  92.  * might be a negative dentry which has no information associated with
  93.  * it */
  94.  
  95.  
  96.  
  97. /* d_flags entries */
  98. #define DCACHE_AUTOFS_PENDING 0x0001    /* autofs: "under construction" */
  99. #define DCACHE_NFSFS_RENAMED  0x0002    /* this dentry has been "silly
  100.                      * renamed" and has to be
  101.                      * deleted on the last dput()
  102.                      */
  103.  
  104. /*
  105.  * d_drop() unhashes the entry from the parent
  106.  * dentry hashes, so that it won't be found through
  107.  * a VFS lookup any more. Note that this is different
  108.  * from deleting the dentry - d_delete will try to
  109.  * mark the dentry negative if possible, giving a
  110.  * successful _negative_ lookup, while d_drop will
  111.  * just make the cache lookup fail.
  112.  *
  113.  * d_drop() is used mainly for stuff that wants
  114.  * to invalidate a dentry for some reason (NFS
  115.  * timeouts or autofs deletes).
  116.  */
  117. static __inline__ void d_drop(struct dentry * dentry)
  118. {
  119.     list_del(&dentry->d_hash);
  120.     INIT_LIST_HEAD(&dentry->d_hash);
  121. }
  122.  
  123. static __inline__ int dname_external(struct dentry *d)
  124. {
  125.     return d->d_name.name != d->d_iname; 
  126. }
  127.  
  128. /*
  129.  * These are the low-level FS interfaces to the dcache..
  130.  */
  131. extern void d_instantiate(struct dentry *, struct inode *);
  132. extern void d_delete(struct dentry *);
  133.  
  134. /* allocate/de-allocate */
  135. extern struct dentry * d_alloc(struct dentry * parent, const struct qstr *name);
  136. extern void prune_dcache(int);
  137. extern void shrink_dcache_sb(struct super_block *);
  138. extern void shrink_dcache_parent(struct dentry *);
  139. extern int d_invalidate(struct dentry *);
  140.  
  141. #define shrink_dcache() prune_dcache(0)
  142.  
  143. /* dcache memory management */
  144. extern int  select_dcache(int, int);
  145. extern void shrink_dcache_memory(int, unsigned int);
  146. extern void check_dcache_memory(void);
  147. extern void free_inode_memory(int);    /* defined in fs/inode.c */
  148.  
  149. /* only used at mount-time */
  150. extern struct dentry * d_alloc_root(struct inode * root_inode, struct dentry * old_root);
  151.  
  152. /* test whether root is busy without destroying dcache */
  153. extern int is_root_busy(struct dentry *);
  154.  
  155. /*
  156.  * This adds the entry to the hash queues.
  157.  */
  158. extern void d_rehash(struct dentry * entry);
  159. /*
  160.  * This adds the entry to the hash queues and initializes "d_inode".
  161.  * The entry was actually filled in earlier during "d_alloc()"
  162.  */
  163. static __inline__ void d_add(struct dentry * entry, struct inode * inode)
  164. {
  165.     d_rehash(entry);
  166.     d_instantiate(entry, inode);
  167. }
  168.  
  169. /* used for rename() and baskets */
  170. extern void d_move(struct dentry * entry, struct dentry * newdentry);
  171.  
  172. /* appendix may either be NULL or be used for transname suffixes */
  173. extern struct dentry * d_lookup(struct dentry * dir, struct qstr * name);
  174.  
  175. /* validate "insecure" dentry pointer */
  176. extern int d_validate(struct dentry *dentry, struct dentry *dparent,
  177.               unsigned int hash, unsigned int len);
  178.  
  179. /* write full pathname into buffer and return start of pathname */
  180. extern char * d_path(struct dentry * entry, char * buf, int buflen);
  181.  
  182. /* Allocation counts.. */
  183. static __inline__ struct dentry * dget(struct dentry *dentry)
  184. {
  185.     if (dentry)
  186.         dentry->d_count++;
  187.     return dentry;
  188. }
  189.  
  190. extern void dput(struct dentry *);
  191.  
  192. #endif /* __KERNEL__ */
  193.  
  194. #endif    /* __LINUX_DCACHE_H */
  195.